var pagination = 30;
var max = 5;
var d = 620;
/**
 * Get pages num
 * @param {Object} len
 * @param {Object} pagination
 */
var getPages = function(len, pagination) {
	return len % pagination > 0 ? parseInt(len / pagination) + 1 : parseInt(len / pagination);
}
/**
 * Convert to timestamp
 * @param {Object} d
 * @param {Object} options
 */
var getTimeStamp = function(d, options) {
	d = d || new Date();
	if(!(d instanceof Date)) {
		d = new Date(d);
	}

	var dateSep = '-';
	var timeSep = ':';
	if(options) {
		if(options.dateSep) {
			dateSep = options.dateSep;
		}
		if(options.timeSep) {
			timeSep = options.timeSep;
		}
	}
	var date = d.getDate();
	if(date < 10) {
		date = '0' + date;
	}
	var month = d.getMonth() + 1;
	if(month < 10) {
		month = '0' + month;
	}
	var hours = d.getHours();
	if(hours < 10) {
		hours = '0' + hours;
	}
	var mintues = d.getMinutes();
	if(mintues < 10) {
		mintues = '0' + mintues;
	}
	var seconds = d.getSeconds();
	if(seconds < 10) {
		seconds = '0' + seconds;
	}
	return d.getFullYear() + dateSep + month + dateSep + date + ' ' +
		hours + timeSep + mintues + timeSep + seconds;
}

var autofit = function(img, w, h, d) {
	var ratio = w / h;
	if(ratio > 1) {
		img.style.width = d + "px";
		img.style.height = d / ratio + "px";
	} else if(ratio < 1) {
		img.style.width = d * ratio + "px";
		img.style.height = d + "px";
	} else {
		img.style.width = d + "px";
		img.style.height = d + "px";
	}
}

var quick = function(array, left, right) {
	var index;
	if(array.length > 1) {
		index = partition(array, left, right);

		if(left < index - 1) {
			quick(array, left, index - 1);
		}

		if(index < right) {
			quick(array, index, right);
		}
	}
}

var partition = function(array, left, right) {
	var pivot = array[Math.floor((right + left) / 2)].dist,
		i = left,
		j = right;
	while(i < j) {
		while(array[i].dist < pivot) {
			i++;
		}

		while(array[j].dist > pivot) {
			j--;
		}

		if(i <= j) {
			swap(array, i, j);
			i++;
			j--;
		}
	}
	return i;
}

var swap = function(array, i, j) {
	var temp = array[j];
	array[j] = array[i];
	array[i] = temp;
}

